function chkreg()
{
	//var weburl = window.location.href;//获取当前网址
	var nickname = $('#nickname').val();
	var sex = getRadioValue("sex");
	var mobile = $('#mobile').val();
	
	var password = $('#password').val();
	var repassword = $('#repassword').val();
	var usertype = $('#usertype').val();//用户类型：1普通客户2贷款经理
	var phonecode = $('#phonecode').val();//手机验证码

	//地区选择
	var provinceid = $('#profile_location option:selected').val();
	var province = $('#profile_location option:selected').text();
	var city = $('#profile_sublocation option:selected').text();
	var cityid = $('#profile_sublocation option:selected').val();

	if(nickname == "" || nickname == "请输入您的称呼") {
		alert('请输入您的称呼');
		return;
	}
	var s = 0;
	if(sex == 1 || sex == 2) {
		s == 1;
	}
	if(s = 0){
		alert('请选择性别');
		return;
	}
	if(mobile == "" || mobile == "您的手机号码") {
		alert('请输入手机号码');
		return;
	}
	var tel2 = /^((13[0-9]{9})|(14[0-9]{9})|(15[0-9]{9})|(18[0-9]{9}))$/;
	if(!tel2.test(mobile))
	{
		alert("手机号码格式不正确");
		return;
	}
	if(phonecode == "" || phonecode == "您的验证码") {
		alert('请输入手机验证码');
		return;
	}
	if(password == '') {
		alert('密码不能为空');
		return;
	}
	if(password != repassword) {
		alert('两次密码不一致');
		return;
	}
	if(captchaVerify()){
		var json_data = {
			'nickname':nickname,'sex':sex,'mobile':mobile,
			'password':password,'phonecode':phonecode,
			'usertype':usertype,'provinceid':provinceid,'province':province,
			'city':city,'cityid':cityid
		};
		$.ajax({
		    type: 'GET',  //这里用GET
		    url: jiekou_site_url+'/user/reg_do.html',
		    dataType: 'jsonp',  //类型
		    data: json_data,
		    jsonp: 'jcallback', //jsonp回调参数，必需
		    async: false,
		    success: function(d) { //返回的json数据
				if(d == 2) {
					alert('请勿重复注册');
					return false;
				}else if(d == 3){
					alert('注册失败');
					return false;
				}else if(d == 4){
					alert('短信验证码错误');
					return false;
				}else{
					window.location.href = jiekou_site_url+'/user/center.html';
				}
		    },
		    timeout: 3000
		});
	}
}

function chklogin()
{
	//var weburl = window.location.href;//获取当前网址
	var account = $('#account').val();
	var password = $('#password').val();
	var usertype = $('#usertype').val();//用户类型：1普通客户2贷款经理
	if(usertype == 1){
		var yzm = $('#yzm').val();
	}
	var dlfs = $('#dlfs').val();
	var remeber = $('#remeber').val();
   
	if(account == "" || account == "您的手机号码") {
		alert('请输入手机号码');
		exit;
	}
	var tel2 = /^((13[0-9]{9})|(14[0-9]{9})|(15[0-9]{9})|(18[0-9]{9}))$/;
	if(!tel2.test(account))
	{
		alert("手机号码格式不正确");
		exit;
	}
	if(usertype == 1){
		if(dlfs == 1 && password == "") {
			alert('密码不能为空');
			exit;
		}else if(dlfs == 2 && yzm == ""){
			alert('验证码不能为空');
			exit;
		}else if(dlfs == 1 && password != "") {
			$.post('/user/login_do.html',{'account':account,'password':password,'usertype':usertype},function (d){
				if(d == 4){
					alert('账号与密码不匹配');
					return false;
				}else if(d == 2){
					alert('账号不存在');
					return false;
				}else{	
				   if ($("#remeber").attr("checked") == true){ 
						SetCookie("cookie_account",account);
						SetCookie("cookie_password",password);
						SetCookie("cookie_remeber",1);
					}else{
						delCookie("cookie_account");
						delCookie("cookie_password");
						delCookie("cookie_remeber");
					}
				   if(d.back_url){
					   window.location.href = d.back_url;
					   return false;
				   }else{
					   window.location.href = '/user/center.html';
					   return false;
				   }
				}
			 
			},'json');
		}else if(dlfs == 2 && yzm != "") {
			$.post('/user/login_do.html',{'account':account,'yzm':yzm,'usertype':usertype},function (d){
				if(d == 4){
					alert('账号与密码不匹配');
					return false;
				}else if(d == 3){
					alert('验证码错误');
					return false;
				}else if(d == 2){
					alert('账号不存在');
					return false;
				}else{	
				   if ($("#remeber").attr("checked") == true){ 
						SetCookie("cookie_account",account);
						SetCookie("cookie_password",password);
						SetCookie("cookie_remeber",1);
					}else{
						delCookie("cookie_account");
						delCookie("cookie_password");
						delCookie("cookie_remeber");
					}
				   if(d.back_url){
					   window.location.href = d.back_url;
				   }else{
					   window.location.href = '/user/center.html';
				   }
					return false;
				}
			 
			},'json');
		}
	}else{
		if(password == "") {
			alert('密码不能为空');
			return;
		}
		$.post('/user/login_do.html',{'account':account,'password':password,'usertype':usertype},function (d){
			if(d == 4){
				alert('账号与密码不匹配');
				return false;
			}else if(d == 3){
				alert('密码不能为空');
				return false;
			}else if(d == 2){
				alert('账号不存在');
				return false;
			}else if(d == 5){
				alert('抱歉，您账号已被封闭！');
				return false;
			}else if(d == 10){
				alert('非法登录地点！');
				return false;
			}else if(d == 100){
				alert('不在允许登陆时间段内！');
				return false;
			}else{	
			   if ($("#remeber").attr("checked") == true){ 
					SetCookie("cookie_account",account);
					SetCookie("cookie_password",password);
					SetCookie("cookie_remeber",1);
				}else{
					delCookie("cookie_account");
					delCookie("cookie_password");
					delCookie("cookie_remeber");
				}
			   
				//$('#loginmsg').html('登录成功，正在跳转...');
			   window.location.href = '/manager/myclients.html';
			   return false;
			}
		},'json');
	}
}

/**
 * 忘记密码验证码
 * @returns {Boolean}
 */
function chkforgetcode()
{
	var mobile = $('#mobile').val();		
	var phonecode  = $('#phonecode').val();//手机验证码
	var usertype = $('#usertype').val();//用户类型：1普通客户2贷款经理

	if(mobile == "" || mobile == "您的手机号码") {
		alert('请输入手机号码');
		return;
	}
	var tel2 = /^((13[0-9]{9})|(14[0-9]{9})|(15[0-9]{9})|(18[0-9]{9}))$/;
	
	if(!tel2.test(mobile))
	{
		alert("手机号码格式不正确");
		return;
	}
	
	if(phonecode == "" || phonecode == "您的验证码") {
		alert('请输入手机验证码');
		return;
	}
	
	$.post('/user/passwordforget.html',{'mobile':mobile,'phonecode':phonecode,'usertype':usertype},function (d){
		if(d == 2){
			alert('验证码错误'); 
			return false;
		}else if(d == 3){
			alert('你的手机号码不存在,请先注册!');
			return false;
		}else{
				if(usertype == 1){
				//验证正确跳转
					window.location.href = '/user/passwordforget_do.html';		
				}else{
					window.location.href = '/manager/passwordforget_do.html'
				}
				return false;
		 }	
	});
}

/**
 * 重置密码验证
 * @returns {Boolean}
 */
function resetpwd()
{
	var newpass = $('#newpass').val();
    var renewpass =$('#renewpass').val();
    if(newpass == ""){
    	alert('新密码不能为空');
    	return false;
    }
    
    if(renewpass == ""){
    	alert('确定新密码不能为空');
    	return false;
    }
    
    if(newpass != renewpass){
    	alert('新密码和确定新密码必须一致');
    	return false;
    }
    //执行验证
    $.post('/user/resetpassword.html',{'newpass':newpass,'renewpass':renewpass},function (d){
    	if(d==1){
    		alert('密码修改成功');
    		window.location.href = '/user/center.html';	
    	}else if(d==3){
    		alert('密码修改成功');
    		window.location.href = '/kefu/index/index.html';
    	}else{
    		alert('密码修改失败');
        	return false;
    	}
	});
    
}

/**
 * 发送验证码
 * @returns {Boolean}
 */
function regcode()
{
	var mobile = $('#mobile').val();
	var msgtype = $('#msgtype').val();//发送短信的类别：1、贷款申请2、注册
	var randcode = $('#randcode').val();
	
	if(mobile == "" || mobile == "您的手机号码") {
		alert('请输入手机号码');
		return;
	}
	var tel2 = /^((13[0-9]{9})|(14[0-9]{9})|(15[0-9]{9})|(18[0-9]{9}))$/;
	if(!tel2.test(mobile))
	{
		alert("手机号码格式不正确");
		return;
	}
	if(msgtype!=2 || captchaVerify()){//验证码验证通过
		document.getElementById("codemsg").value="正在发送...";
		$.post('/user/sms_code_reg.html',{'mobile':mobile,'msgtype':msgtype,'randcode':randcode},function (d){
			if(d == 1) {
				document.getElementById("codemsg").value="验证码已发送";
				return;
			}
			if(d == 2) {
				document.getElementById("codemsg").value="号码已注册";
				return;
			}
			if(d == 8) {
				document.getElementById("codemsg").value="操作过于频繁";
				alert("抱歉，因系统繁忙无法提交，如有疑问请拨打：400-77777-11");
				return;
			}
			if(d == 9) {
				document.getElementById("codemsg").value="不支持国外注册";
				alert("抱歉，因系统繁忙无法提交，如有疑问请拨打：400-77777-11");
				return;
			}
			if(d == 10) {
				document.getElementById("codemsg").value="图形验证码错误";
				setCaptchaImg();
				return;
			}else{
				document.getElementById("codemsg").value="验证码发送失败";
				return;
			}
		});
	}
}

/**
 * 手机验证
 * @returns {Boolean}
 */
function chkmobile(){
	var mobile = $('#mobile').val();
	var reg2 = /^((13[0-9]{9})|(14[0-9]{9})|(15[0-9]{9})|(18[0-9]{9}))$/;
	if(!reg2.test(mobile))
	{
		$('#regmsg').html("<span style='color:red;'>手机号码格式错误</span>");
		return false;
	}else{
		$('#regmsg').html("");
	}
}

function getRadioValue(radioName) {
    var chkRadio = document.getElementsByName(radioName);
    for (var i = 0; i < chkRadio.length; i++) {
        if (chkRadio[i].checked)
            return chkRadio[i].value;
    }
}




/*
登录页清空功能
*/
function cancel()
{
	$('#account').val('');
	$('#password').val('');
	$('#code').val('');
}
/*
登录页验证码刷新
*/
function refurbish(){
     var img = document.getElementById("varImg"); 
     img.src = "inc/code.php?" + Math.random(); 
} 
/*
菜单列表JS代码
*/
function open_close_li(id)
{
	if(document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "block";
	}
	else {
		document.getElementById(id).style.display = "none";
	}
}
function open_close_item(id)
{
	if(document.getElementById(id).className == "openitem") {
		document.getElementById(id).className = "closeitem";
	}
	else {
		document.getElementById(id).className = "openitem";
	}
}
/*
时间代码
*/
function reloop()
{
	
	var time = new Date( ); //获得当前时间
	//获得年、月、日，Date()函数中的月份是从0－11计算
	var year = time.getYear(); 
	var month = time.getMonth()+1;
	var date = time.getDate();
	//获得小时、分钟、秒
	var hour = time.getHours();  
	var minute = time.getMinutes();
	var second = time.getSeconds();
	//获得一个星期中的第几天,西方的星期是从星期日开始，星期六结束
	var day = time.getDay();
	//如果分钟只有1位，补0显示
	if (minute < 10)
	minute="0"+minute;
	//如果秒数只有1位，补0显示
	if (second < 10)
	second="0"+second;
	//按12小时制显示
	if (hour>24) {
		hour=hour-24;
	}
	var weekday = 0;
	//firefox下的getyear是从1900年开始的
	year = (year < 1900)?(1900+year):year;
	
	switch(time.getDay()) {
		case 0:
			weekday = "星期日";
		break;
		case 1:
			weekday = "星期一";
		break;
		case 2:
			weekday = "星期二";
		break;
		case 3:
			weekday = "星期三";
		break;
		case 4:
			weekday = "星期四";
		break;
		case 5:
			weekday = "星期五";
		break;
		case 6:
			weekday = "星期六";
		break;
	}
	
	document.getElementById("t").innerHTML="今天是："+year+"年"+month+"月"+date+"日"+weekday+"  "+hour+"时"+minute+"分"+second+"秒";
	setTimeout("reloop()",1000);
}

function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 10; //此 cookie 将被保存 10天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) 
    	 return unescape(arr[2]);return null;
}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

/**
 * 判断单选是否选中
 * @param rname
 * @returns {Number}
 */
function fn(rname){//定义一个函数 
	   var radio1=document.getElementsByName(rname);
       var flag1 = 0;
	   for(var i=0;i<radio1.length;i++)
	   {
	         if(radio1.item(i).checked==true)
	         {
	             flag1=1;
	             break;
	         }
	   }
	   return flag1;
}

function Counter(nMax,nInterval)
{
	this.maxTime=nMax;
	this.interval=nInterval;
	this.objId="timer";
	this.obj=null;
	this.num=this.maxTime;
	this.timer=null;
	this.start=function()
	{ 
		this.obj=document.getElementById(this.objId);
		if(this.num>0) setTimeout(this.run,this.interval*1000);
	};
	this.run=function()
	{
		if(myCounter.num>0) 
		{
			myCounter.num--;
			myCounter.obj.innerHTML=myCounter.num;
			myCounter.timer=setTimeout(myCounter.run,myCounter.interval*1000);
		}else{
			clearTimeout(myCounter.timer);
		}
	};
	this.show=function()
	{
		document.write("<span id="+this.objId+">"+this.num+"</span>");
		this.obj=document.getElementById(this.objId);
	//alert(this.obj.innerHTML);
	}
}

function setCaptchaImg(){
	$('#randcodeimg').attr('src', '/captchacode/index.html?type=user_reg&height=30&r=' + Math.random());
	setTimeout(
			function(){
				bindVerify(false);
			},500);
}
function bindVerify(repeat){
	var mobile = $('#mobile').val();
	var reg = /^((13[0-9]{9})|(14[0-9]{9})|(15[0-9]{9})|(18[0-9]{9}))$/;
	if(mobile!='' && reg.test(mobile)){
		$.ajax({  
	        type:"POST",  
	        url:'/captchacode/bind_do.html',
	        data:{'type':'user_reg','key':mobile},  
	        success: function(msg){
	             if(msg.toString().trim() != '1' && repeat==true){  
	            	 setCaptchaImg();//重置验证码
	             }
	        }
	    });
	}
}
function captchaVerify(){
	var flag = false;
	var randcode = $('#randcode').val();
	if(randcode==''){
		alert('请先输入图形验证码');
		$('#randcode').focus();
		return false;
	}
	var reg = /^[a-zA-Z\d]{4}$/;
	if(randcode!='' && reg.test(randcode)){
		var mobile = $('#mobile').val();
	    $.ajax({  
	        type:"POST",  
	        url:'/captchacode/bind_verify.html',
	        async:false,//同步方法，如果用异步的话，flag永远为1
	        data:{'type':'user_reg','randcode':randcode,'key':mobile},  
	        success: function(msg){
	             if(msg.toString().trim() == '1'){  
	                 flag = true;
	             }  
	        }
	    });
	}
    if(!flag){
    	alert('图形验证码无效');
    	setCaptchaImg();
    	$('#randcode').focus();
    }
    return flag;
}